package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import form.ConnectionDB;

import model.Tinhthanh;

public class TinhthanhDAO {

	public static ArrayList<Tinhthanh> select() throws ClassNotFoundException,
			SQLException {
		Connection connection = ConnectionDB.getConnection();
		ArrayList<Tinhthanh> arrTinhthanh = new ArrayList<>();
		String sql = "select * from Tinhthanh";
		PreparedStatement ps = connection.prepareStatement(sql);
		ResultSet resultSet = ps.executeQuery();
		while (resultSet.next()) {
			String idType = resultSet.getString(1);
			String name = resultSet.getString(2);
			arrTinhthanh.add(new Tinhthanh(idType, name));
		}
		connection.close();

		return arrTinhthanh;

	}

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
//		ArrayList<Tinhthanh> arrTinhthanh= TinhthanhDAO.select();
//		for (Tinhthanh tinhthanh : arrTinhthanh) {
//			System.out.println(tinhthanh.toString());
//		}
	}

}
